/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __TEXTSTREAMBUFFER_H__
#define __TEXTSTREAMBUFFER_H__

#include <vector>
#include <iterator>
#include <algorithm>
#include "TextStream.h"

namespace liba
{
namespace textstream
{

/** This class returns "raw memory". It is used by network operations and
	other services that use C-style const void* or const char* arguments. */
template<class Sym>
class Buffer : public TextOStream<Sym>
{
	std::vector<char> buffer;
public:
	virtual void print(const Sym * begin, const Sym * end)
	{
		buffer.reserve( buffer.size() + (end - begin)*sizeof(Sym) );
		std::copy( begin, end, std::back_inserter( buffer ) );
	}
	virtual void flush()
	{}
	const std::vector<char> & get_buffer()const
	{
		return buffer;
	}
	void clear()
	{
		buffer.clear();
	}
};

} // namespace textstream
} // namespace liba

using namespace liba;

#endif //__TEXTSTREAMBUFFER_H__